<?php
/**
 * 首页管理控制器
 * Created by PhpStorm.
 * User: xiangpeng
 * Date: 2017/1/4
 * Time: 22:32
 */

namespace Home\Controller;


use Common\Model\LoginModel;
use Think\Controller;

class LoginController extends  Controller
{
    //登录页面
    public function index ()
    {
        if(IS_POST){
            //实例化模型
            $loginModel = new LoginModel();
            $res = $loginModel->isLogin();
            if($res['status']=='success'){
                $this->success('登录成功',U('Home/Index/index'));die;
            }else{
                $this->error($res['message']);die;
            }
        }
        //加载模板
        $this->display( 'login' );
    }

    //注册页面
    public function register ()
    {
        if(IS_POST){
            //实例化模型
            $loginModel= new LoginModel();
            $res =$loginModel->register();
            //dd($res);die;
            if($res['status']=='success'){
                $this->success($res['message'],U('Login/index'));die;
            }else{
                $this->error($res['message']);die;
            }
        }

        //加载模板
        $this->display();
    }

    //验证码类
    public function code(){
        //动态设置的方式
        $Verify =     new \Think\Verify();
        $Verify->fontSize = 30;
        $Verify->length   = 3;
        $Verify->useNoise = false;
        $Verify->entry();
    }

    //退出
    public function out(){
        //清空当前session
        session(null);
        //销毁session
        session('[destroy]');
        //退出成功提示
        $this->success('退出成功',U('Home/Index/index'));
    }
}